package com.jeespring.shardingjdbc.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeespring.shardingjdbc.entity.User;
import com.jeespring.shardingjdbc.mapper.UserMapper;
import com.jeespring.shardingjdbc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 张朝阳
 * @description UserServiceImpl
 * @date 2021/11/16 0:26:26
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> select(User user) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("id",user.getId());
        return userMapper.selectList(wrapper);
    }

    @Override
    public IPage<User> selectPage(User user, int pageNumber, int pageSize) {
        IPage<User> page = new Page<>();
        Wrapper<User> wapper = new QueryWrapper<>();
        return userMapper.selectPage(page, wapper);
    }

    @Override
    public List<User> selectAll() {
        return userMapper.selectAll();
    }

    @Override
    public int insert(User user) {
        return userMapper.insert(user);
    }

    @Override
    public int delete(User user) {
        Wrapper<User> wapper = new QueryWrapper<>();
        return userMapper.delete(wapper);
    }

    @Override
    public int update(User user) {
        UpdateWrapper<User> wapper = new UpdateWrapper<>();
        wapper.eq("id", 3);
        return userMapper.update(user, wapper);
    }
}